<?php
/**
 *
 *
 *
 */
namespace Yz\modules\Uploads;

class Model_Upload
    extends \Yz\modules\Generic\Model_Default
    implements \Yz_Model_Interface
{

    protected $uploadPath;

    /**************************
     *      Public methods    *
     **************************/

    /**
     *
     *  @return Item
     *  @throw
     */
    public function processUpload($uploadName)
    {
        $uploadPath = $this->getUploadPath();
        $action = $this->selectAction('Upload');
        $values = $action
            ->setUploadName($uploadName)
            ->setUploadPath($uploadPath)
            ->execute()
            ->fetch()
            ;
        $item = $this->selectItem('UploadedFile');
        return $item->assignValues($values);
    }


    public function getUploadPath()
    {
        $uploadPath =& $this->uploadPath;
        if (null === $uploadPath) {
            $uploadPath = 'www/uploads';
        }
        return $uploadPath;
    }

    public function setUploadPath($uploadPath)
    {
        $path = \Yz_String::testNotEmpty($uploadPath);
        $this->uploadPath = $path;
        return $this;
    }

    /*****************************
     *      Protected methods    *
     *****************************/

}
